package org.glowacki;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

public class testParseString {

	public static void main(String[] args) {
		// String dateStr = "Aug 3, 2008 21:25:00 +0100";
		/*
		 * String[] dateStrings = new
		 * String[]{"Sat, 3 May 2008 12:58:13 -0600 (MDT)",
		 * "Aug 3, 2008 21:25:00 +100", "Wed, 30 Apr 2008 11:28:42 -0500",
		 * "Wed, 30 Apr 79 11:28:42", "Sat, 3 May 2008 19:49:57 +0200 (CEST)"};
		 */

		/*
		 * String[] patterns = new String[] {"\\(.*\\)\\([+-]\\d{3,4}\\)$",
		 * "([+-]\\d{3,4}$", "\\(.*\\)\\([+-]\\d{3,4}\\)\\(\\w{3,4})\\)$"};
		 */
		String dateString = "Sat, 3 May 2008 19:49:57 +0200 (CEST)";
		String patternString = "(.*)([+-]\\d{3,4})( \\(\\w{3,4}\\))$";

		Pattern pattern = Pattern.compile(patternString);
		Matcher matcher = pattern.matcher(dateString);
		if (matcher.matches()) {
			System.out.println("Matches");
			String newString = StringUtils.removeEnd(dateString, matcher.group(3));
			System.out.println(newString);
		}
		else {
			System.out.println("NO MATCH");

		}
	}
}

/*
 * String removedOffset = dateStr.substring(0, matcher.start()); String offset =
 * dateStr.substring(matcher.start()); String hours, minutes; if(offset.length()
 * == 4){ hours = offset.substring(0,2); minutes = offset.substring(2,4); } else
 * { hours = offset.substring(0,3); minutes = offset.substring(3,5); } String
 * newToken = hours + ":" + minutes; dateStr = removedOffset + newToken; }
 * Calendar cal = null; try { //cal = CalendarParser.parse(dateStr,
 * matcher.matches() ? CalendarParser.DD_MM_YY : 0); cal =
 * CalendarParser.parse(dateStr); } catch(Exception e){
 * System.err.println("Exception: " + e.getMessage()); e.printStackTrace();
 * System.exit(1); } System.out.println("Returned Cal: " +
 * CalendarParser.prettyString(cal)); System.exit(0); }
 */
